package com.nf.controller.manage;

import com.google.gson.Gson;
import com.nf.controller.BaseServlet;
import com.nf.dao.ShowInfoDao;
import com.nf.dao.impl.ShowInfoDaoImpl;
import com.nf.entity.ShowInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 编写servlet ，实现添加放映计划
 */
@WebServlet("/api/ShowAddServlet.do")
public class ShowAddServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String filmName=req.getParameter("filmName");
        String hallName=req.getParameter("hallName");
        String showDate=req.getParameter("showDate");
        String startTime=req.getParameter("startTime");
        String endTime=req.getParameter("endTime");
        Float price= Float.valueOf(req.getParameter("price"));
        int filmId= Integer.parseInt(req.getParameter("filmId"));
        int hallId= Integer.parseInt(req.getParameter("hallId"));

        ShowInfo show=new ShowInfo();
        show.setFilmName(filmName);
        show.setHallName(hallName);
        show.setShowDate(showDate);
        show.setStartTime(startTime);
        show.setEndTime(endTime);
        show.setPrice(price);
        show.setFilmId(filmId);
        show.setHallId(hallId);

        ShowInfoDao dao=new ShowInfoDaoImpl();
        int id= dao.add(show);

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        out.print(new Gson().toJson(successJson(id)));

        out.flush();
        out.close();
    }
}
